package sunn.android.Conn;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

import android.util.Log;

public class AndroidNetwork 
{
	public static final String DEBUG_TAG = "NETWORK";
	
	public static String getLocalIpAddress() 
	{
		try 
		{
			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) 
			{
				NetworkInterface ni = en.nextElement();

				for (Enumeration<InetAddress> enumIpAddr = ni.getInetAddresses(); enumIpAddr.hasMoreElements();) 
				{
					InetAddress inetAddress = enumIpAddr.nextElement();

					if (!inetAddress.isLoopbackAddress()) 
					{
						return inetAddress.getHostAddress();
					}
				}
			}
		} 
		catch (SocketException ex) 
		{
			Log.e(DEBUG_TAG, ex.toString());
		}

		return new String();
	}
	
}
